﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class user
    {
        public static dynamic editUserInfo(string username, string nickname, string email,string motto,
            bool publicPersonalInfo, string name, string school, bool? sex, DateTime? birthday)
        {
            var sql = new Sql.SqlDataContext();
            var u = sql.User.FirstOrDefault(row => row.username.ToLower() == username.ToLower());
            if (u == null) return new
                {
                    success = false,
                    msg = "用户不存在"
                };
            u.nickname = nickname;
            u.email = email;
            u.motto = motto;
            u.publicPersonalInfo = publicPersonalInfo;
            if (string.IsNullOrEmpty(u.sid)) // Student can't modify student info
            {
                u.name = name;
                u.school = school;
                u.sex = sex;
                u.birthday = birthday;
            }
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
